import type { App } from 'vue'
const message = useMessage() // 消息弹窗

export function copy(app: App<Element>) {
  app.directive('copy', (el, binding) => {
    el.$copy = function () {
      const textarea = document.createElement('textarea')
      textarea.value = binding.value
      document.body.appendChild(textarea)
      textarea.select()
      document.execCommand('Copy')
      document.body.removeChild(textarea)
      message.success('复制成功')
    }
    el.addEventListener('click', el.$copy)
  }),
    (el) => {
      el.removeEventListener('click', el.$copy)
    }
}
